/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.additional;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.list.ListCellRenderer;
import datamodel.Order;

/**
 *
 * @author Kvest
 */
public class OrderListRenderer extends Container implements ListCellRenderer
{    
    private TextArea content;
    private Label focusComponent = new Label();
    
    public OrderListRenderer()
    {
        setLayout(new BorderLayout());
        setUIID("ListRenderer");
        
        getStyle().setMargin(Component.TOP, 0);
        getStyle().setMargin(Component.BOTTOM, 0);
        getSelectedStyle().setMargin(Component.TOP, 0);
        getSelectedStyle().setMargin(Component.BOTTOM, 0);
        getStyle().setPadding(Component.TOP, 0);
        getStyle().setPadding(Component.BOTTOM, 0);
        getSelectedStyle().setPadding(Component.TOP, 0);
        getSelectedStyle().setPadding(Component.BOTTOM, 0);
        
        content = new TextArea("",2,30);
        content.setEditable(false);
        content.setRows(2);
        content.setGrowByContent(false);
        content.setFocusable(false);
        content.setUIID("ListRenderer");
        content.getStyle().setMargin(Component.TOP, 0);
        content.getStyle().setMargin(Component.BOTTOM, 0);
        content.getSelectedStyle().setMargin(Component.TOP, 0);
        content.getSelectedStyle().setMargin(Component.BOTTOM, 0);
        content.getStyle().setPadding(Component.TOP, 0);
        content.getStyle().setPadding(Component.BOTTOM, 0);
        content.getSelectedStyle().setPadding(Component.TOP, 0);
        content.getSelectedStyle().setPadding(Component.BOTTOM, 0);
        addComponent(BorderLayout.CENTER, content);
        
        focusComponent.setUIID("ListRendererFocus");
        focusComponent.setFocus(true);
    }
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
    {     
        setFocus(isSelected);
        if (value != null && (value instanceof Order))
        {
            content.setText(((Order)value).getShortDescription());
        }
        
        return this;
    }
    
    public Component getListFocusComponent(List list) 
    {
        return focusComponent;
    }
}
